package com.cqfan.cloud.office.libreoffice.service;

import org.apache.commons.io.IOUtils;
import org.jodconverter.core.DocumentConverter;
import org.jodconverter.core.office.OfficeException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.*;

/**
 * @author JiaLing.Fan
 * @version 1.0
 * @date 2024-05-13 14:01
 * @description ConverterService
 */
@Service
public class ConverterService {

    @Resource
    private DocumentConverter documentConverter;


    public void convert(InputStream inputStream, OutputStream outputStream,String type) throws OfficeException {
        documentConverter.convert(inputStream).to(outputStream)
                .as(documentConverter.getFormatRegistry()
                        .getFormatByExtension(type)).execute();
            IOUtils.closeQuietly(inputStream);
    }

}
